<?php
class Category_lib {
	var $xml = '';
	var $data = array();
	var $root = array();
	var $items = array();
	var $xmlbody = '<?xml version="1.0"  encoding="utf-8"?>
<root>
	<majorsort code="10" name="安全技术">
<!--		<subclass code="10001" name="病毒木马" />  -->
		<subclass code="10002" name="黑客攻防" />
		<subclass code="10003" name="网络安全" />
		<subclass code="10004" name="系统安全" />
		<subclass code="10005" name="其它" />
	</majorsort>
	<majorsort code="11" name="存储 ">
		<subclass code="11001" name="Dell" />
		<subclass code="11002" name="EMC" />
		<subclass code="11003" name="HP" />
		<subclass code="11004" name="IBM" />
		<subclass code="11005" name="Microsoft" />
		<subclass code="11006" name="SUN" />
		<subclass code="11007" name="Veritas" />
		<subclass code="11008" name="其它" />
	</majorsort>
	<majorsort code="12" name="操作系统 ">
		<subclass code="12001" name="DOS" />
		<subclass code="12002" name="Linux" />
		<subclass code="12003" name="MacOS" />
		<subclass code="12004" name="OS" />
		<subclass code="12005" name="Solaris" />
		<subclass code="12006" name="Ubuntu" />
		<subclass code="12007" name="Unix" />
		<subclass code="12008" name=" Windows Server" />
		<subclass code="12009" name="桌面系统" />
		<subclass code="12010" name="其它" />
	</majorsort>
	<majorsort code="13" name="服务器应用 ">
		<subclass code="13001" name="DNS" />
		<subclass code="13002" name="FTP" />
		<subclass code="13003" name="Mail服务器" />
		<subclass code="13004" name=" Proxy" />
		<subclass code="13005" name="VPN" />
		<subclass code="13006" name="Web服务器" />
		<subclass code="13007" name="群集服务" />
		<subclass code="13008" name="虚拟化" />
		<subclass code="13009" name="其它" />
	</majorsort>
	<majorsort code="14" name="行业">
		<subclass code="14001" name="餐饮零售" />
		<subclass code="14002" name="电信" />
		<subclass code="14003" name="电子政务" />
		<subclass code="14004" name="互联网" />
		<subclass code="14005" name="交通" />
		<subclass code="14006" name="教育" />
		<subclass code="14007" name="金融" />
		<subclass code="14008" name="旅游" />
		<subclass code="14009" name="嵌入式" />
		<subclass code="14010" name=" 外包" />
		<subclass code="14011" name=" 网络游戏" />
		<subclass code="14012" name=" 物流" />
		<subclass code="14013" name=" 医疗" />
		<subclass code="14014" name="制造" />
		<subclass code="14015" name="咨询" />
	</majorsort>
	<majorsort code="15" name="课程资源">
		<subclass code="15001" name="3G/移动开发" />
		<subclass code="15002" name="C/C++" />
		<subclass code="15003" name=" Java" />
		<subclass code="15004" name=".Net" />
		<subclass code="15005" name="PHP" />
		<subclass code="15006" name="嵌入式" />
		<subclass code="15007" name="软件测试" />
		<subclass code="15008" name="数据库" />
		<subclass code="15009" name="网络管理" />
		<subclass code="15010" name="网页制作" />
		<subclass code="15011" name="游戏开发" />
		<subclass code="15012" name="专业指导" />
	</majorsort>
	<majorsort code="16" name="开发技术 ">
		<subclass code="16001" name="Actionscript" />
		<subclass code="16002" name="C" />
		<subclass code="16003" name="C#" />
		<subclass code="16004" name=" C++" />
		<subclass code="16005" name="Delphi" />
		<subclass code="16006" name="Java" />
		<subclass code="16007" name="Javascript" />
		<subclass code="16008" name="Perl" />
		<subclass code="16009" name="PHP" />
		<subclass code="16010" name="Python" />
		<subclass code="16011" name="VB" />
		<subclass code="16012" name="Web开发" />
		<subclass code="16013" name="硬件开发" />
		<subclass code="16014" name="其它" />
	</majorsort>
	<majorsort code="17" name="考试认证">
		<subclass code="17001" name="微软认证" />
		<subclass code="17002" name="思科认证" />
		<subclass code="17003" name="华为认证" />
		<subclass code="17004" name="Oracle认证" />
		<subclass code="17005" name="Linux/Unix认证" />
		<subclass code="17006" name="软考等考" />
		<subclass code="17007" name="其它" />
	</majorsort>
	<majorsort code="18" name="数据库">
		<subclass code="18001" name="Access" />
		<subclass code="18002" name="DB2" />
		<subclass code="18003" name="Informix" />
		<subclass code="18004" name=" Memcached" />
		<subclass code="18005" name="MongoDB" />
		<subclass code="18006" name="MySQL" />
		<subclass code="18007" name="Oracle" />
		<subclass code="18008" name="PostgreSQL" />
		<subclass code="18009" name="Redis" />
		<subclass code="18010" name="SQLite" />
		<subclass code="18011" name=" SQLServer" />
		<subclass code="18012" name="Sybase" />
		<subclass code="18013" name="其它" />
	</majorsort>
	<majorsort code="19" name="网络技术">
		<subclass code="19001" name="网管软件" />
		<subclass code="19002" name="网络基础" />
		<subclass code="19003" name="网络监控" />
		<subclass code="19004" name="网络设备" />
		<subclass code="19005" name="系统集成" />
		<subclass code="19006" name="综合布线" />
		<subclass code="19007" name="其它" />
	</majorsort>
	<majorsort code="20" name="信息化 ">
		<subclass code="20001" name="电子商务" />
		<subclass code="20002" name="管理软件" />
		<subclass code="20003" name="IT管理" />
		<subclass code="20004" name="企业管理" />
		<subclass code="20005" name="项目管理" />
		<subclass code="20006" name="其它" />
	</majorsort>
	<majorsort code="21" name="移动开发">
		<subclass code="21001" name="Android" />
		<subclass code="21002" name="bada" />
		<subclass code="21003" name="BlackBerry" />
		<subclass code="21004" name="Flash" />
		<subclass code="21005" name="HTML5" />
		<subclass code="21006" name="iOS" />
		<subclass code="21007" name="JavaME" />
		<subclass code="21008" name="MeeGo" />
		<subclass code="21009" name="QT" />
		<subclass code="21010" name=" Symbian" />
		<subclass code="21011" name=" webOS" />
		<subclass code="21012" name="WindowsPhone" />
		<subclass code="21013" name="其它" />
	</majorsort>
</root>
';
	function __construct() {
		
	}
	public function load (){
		if(empty($this->xml))
		{ 
			$this->xml = simplexml_load_string($this->xmlbody);
			$this->data = $this->getdata();
		}
	}
	
	function get_category_name($catid)
	{
		$this->load();
		$majorsort_code = substr ( $catid, 0, 2 );
		$categoryname = $this->get_link_html($majorsort_code,$this->root [$majorsort_code]) . ' - ' . $this->get_link_html($catid,$this->items [$majorsort_code] [$catid]) ;
		return $categoryname;
	}
	
	function get_link_html($catid,$name)
	{
		if(strlen($catid)==2)
		$catid = $catid."000";
		$link = "/source/slist/$catid";
		return "<a href=\"$link\">$name</a>";
	}
	
	function get_categories_html()
	{
		$this->load();
		$ret = array();
		foreach( $this->root as $code =>$name)
		{
			$html = "";
			if(!in_array($code,array("21","16"))) continue;
			foreach($this->items[$code] as $scode => $sname )
			{
				$ret[$code][$scode] = $this->get_link_html($scode,$sname);
			}
			$ret[$code]['html'] = $this->get_link_html($code,$name);
				
		}
		return $ret;
	}
	function getdata(){
		foreach ($this->xml->majorsort as $item){
			$majorsotr = get_object_vars($item);
			$attributes = $majorsotr['@attributes'];
			$this->root[$attributes['code']] = $attributes['name'];
			foreach($majorsotr['subclass'] as $subclass){
				$tmp = get_object_vars($subclass);
				$this->items[$attributes['code']][$tmp['@attributes']['code']] = $tmp['@attributes']['name'];
			}
		}
		$data = array('root'=>$this->root,'items'=>$this->items);
		return $data;
	}
}
?>